package com.android.jianboshi.ui.fragment;

import android.Manifest;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.view.View;
import android.widget.LinearLayout;

import com.android.baselibrary.tool.XXPermisionUtil;
import com.android.baselibrary.ui.BaseFragment;
import com.android.jianboshi.R;
import com.android.jianboshi.ui.activity.Boxing_FreeStyleActivity;
import com.android.jianboshi.ui.activity.Boxing_PowerActivity;
import com.android.jianboshi.ui.activity.Boxing_Speed_SelectTimeActivity;
import com.android.jianboshi.ui.activity.Device_ListActivity;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class HomeMainFragment extends BaseFragment {

    @BindView(R.id.ll_head)
    LinearLayout ll_head;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main;
    }

    @Override
    protected void initView() {
        ImmersionBar.with(this).titleBar(ll_head).statusBarDarkFont(false).navigationBarDarkIcon(false).init();

    }

    @Override
    protected void initData() {
//        List<String> permission = getNeedPermissions();
//        XXPermisionUtil.requstPermision(mContext, new OnPermissionCallback() {
//            @Override
//            public void onGranted(List<String> permissions, boolean all) {
////                BluetoothHelper bluetoothHelper = new BluetoothHelper();
////                if (bluetoothHelper.isOpen()) {
////                    Log.d("bt isOpen");
////                    bluetoothHelper.scan();
////                } else {
////                    Log.d("bt not Open");
////                }
//            }
//        }, permission.toArray(new String[permission.size()]));
    }

    @OnClick({R.id.tv_freestyle, R.id.tv_power, R.id.tv_speed, R.id.iv_bluetooth})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_freestyle:
                StartActivity(Boxing_FreeStyleActivity.class);
                break;
            case R.id.tv_power:
                StartActivity(Boxing_PowerActivity.class);
                break;
            case R.id.tv_speed:
                StartActivity(Boxing_Speed_SelectTimeActivity.class);
                break;
            case R.id.iv_bluetooth:
                StartActivity(Device_ListActivity.class);

        }
    }

    //需要进行检测的权限
    private List<String> getNeedPermissions() {
        List<String> list = new ArrayList<>();
        //target sdk版本在29以上的需要精确定位权限才能搜索到蓝牙设备
        if (mContext.getApplicationInfo().targetSdkVersion >= 29) {
            list.add(Manifest.permission.ACCESS_FINE_LOCATION);
            list.add(Manifest.permission.ACCESS_COARSE_LOCATION);
        } else {
            list.add(Manifest.permission.ACCESS_COARSE_LOCATION);
        }
        //Android 12需要
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            list.add(Manifest.permission.BLUETOOTH_SCAN);
            list.add(Manifest.permission.BLUETOOTH_CONNECT);
            list.add(Manifest.permission.ACCESS_COARSE_LOCATION);
        }
        return list;
    }


}
